package com.wsc.springbootmultidevdemo.msg.dlx;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.wsc.springbootmultidevdemo.msg.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 死信队列
 */
public class Sent {
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();

        String exchange = "dlx_test_exc";
        String routingKey = "dlx.save";
        String msg = "hello dlx test";

        //设置了过期时间
        AMQP.BasicProperties properties = new AMQP.BasicProperties().builder()
                .expiration("10000")
                .contentEncoding("utf-8")
                .build();

        channel.basicPublish(exchange,routingKey,properties,msg.getBytes());
        channel.close();
        connection.close();
    }

}
